<?php



defined('BASEPATH') OR exit('No direct script access allowed');

include 'linkdatabase.php';
include 'findInDatabase.php';


class Binput extends CI_Controller {
  public function index(){
	  $buyername=$_GET['buyername'];
	  $schoolId=$_GET['schoolId'];
	  $partId=$_GET['partId'];
	  $title=$_GET['title'];
	  $author=$_GET['author'];
	  $contect=$_GET['contect'];
		$contectId=$_GET['contectId'];
		$openId=$_GET['openId'];
		$date=date("Y-m-d");  
    $status="确认完成";


    $link = linkdatabase::link();
    @mysqli_select_db($link, "book");

		$uid=findInDatabase::finduid($openId);
		if(!$uid){
			$qury="INSERT INTO user (`uid`,`open_id`,`name`,`contact`,`contactId`) VALUES (null,'$openId','$sellername','$contect',      '$contectId')";
		  $res = mysqli_query($link, $qury);
			$uid=findInDatabase::finduid($openId);
      if (!$res) {
        echo 'can not run1';
      }
		}else{
      $qury="UPDATE user SET `name`='$buyername',`contact`='$contect',`contactId`='contectId' WHERE `open_id`='$openId'";
		}

    $sql="INSERT INTO buybook (`bbid`, `title`, `author`, `date`, `school`, `dept`,`status`, `uid`) VALUES (null,'$title','$author','$date','$schoolId','$partId','$status','$uid')";
    $result = mysqli_query($link, $sql);
      if (!$result) {
            echo 'can not run2';
      }else{
				$data="success";
				header(	'Content-Type:text/json');
				echo json_encode($data);
			}

  }
}